<%--
  Created by IntelliJ IDEA.
  User: sofwin
  Date: 2021/9/22
  Time: 11:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<html>
<head>
    <base href="<%=path%>">
    <title>新增用户信息</title>
    <link href="hplus-master/css/bootstrap.min.css?v=3.3.7" rel="stylesheet" />
    <link href="hplus-master/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" />
    <link href="hplus-master/css/animate.css" rel="stylesheet" />
</head>
<body style="overflow-x:hidden">
<div style="padding: 10px 10px;">
<form class="form-horizontal" id="addForm">
    <input type="hidden" name="userId" value="${user.userId}">
    <div class="form-group">
        <label  class="col-sm-2 control-label">登录名</label>
        <div class="col-sm-10">
            <input type="text" name="loginName" value="${user.loginName}" class="form-control" id="loginName1" placeholder="登录名">
        </div>
    </div>
    <div class="form-group">
        <label for="loginPwd" class="col-sm-2 control-label">密码</label>
        <div class="col-sm-10">
            <input type="password" name="loginPwd" value="${user.loginPwd}" class="form-control" id="loginPwd" placeholder="Password">
        </div>
    </div>
    <div class="form-group">
        <label for="loginPwd2" class="col-sm-2 control-label">确认密码</label>
        <div class="col-sm-10">
            <input type="password" name="loginPwd2" value="${user.loginPwd}" class="form-control" id="loginPwd2" placeholder="Password">
        </div>
    </div>
    <div class="form-group">
        <label for="realName" class="col-sm-2 control-label">姓名</label>
        <div class="col-sm-10">
            <input type="text" name="realName" value="${user.realName}" class="form-control" id="realName" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <label for="sex" class="col-sm-2 control-label">性别</label>
        <div class="col-sm-10">
            <select id="sex" name="userSex" class="form-control">
                <option value="0">男</option>
                <option value="1">女</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="userBirthday" class="col-sm-2 control-label">出生日期</label>
        <div class="col-sm-10">
            <input type="text" name="userBirthday" value="${user.userBirthday}" class="form-control" id="userBirthday" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <label for="userIdcard" class="col-sm-2 control-label">身份证</label>
        <div class="col-sm-10">
            <input type="text" name="userIdcard" value="${user.userIdcard}" class="form-control" id="userIdcard" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <label for="mobile" class="col-sm-2 control-label">手机号</label>
        <div class="col-sm-10">
            <input type="text" name="mobile" value="${user.mobile}" class="form-control" id="mobile" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <label for="address" class="col-sm-2 control-label">联系地址</label>
        <div class="col-sm-10">
            <input type="text" name="address" value="${user.address}" class="form-control" id="address" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <label for="status" class="col-sm-2 control-label">状态</label>
        <div class="col-sm-10">
            <select id="status" class="form-control" name="status">
                <option value="0" <c:if test="${user.status==0}">selected</c:if> >启用</option>
                <option value="1" <c:if test="${user.status==1}">selected</c:if>>禁用</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="deptId" class="col-sm-2 control-label">所属部门</label>
        <div class="col-sm-10">
            <select id="deptId" class="form-control" name="deptId">
                <c:forEach items="${depts}" var="dept">
                <option value="${dept.deptId}" <c:if test="${user.deptId==dept.deptId}">selected</c:if> >${dept.deptName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="roleId" class="col-sm-2 control-label">所属角色</label>
        <div class="col-sm-10">
            <select id="roleId" class="form-control" name="roleId">
                <c:forEach items="${roles}" var="role">
                    <option value="${role.roleId}" <c:if test="${user.roleId==role.roleId}">selected</c:if> >${role.roleName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10" align="center">
            <button type="button" class="btn btn-primary save">保存</button>
            <button type="reset" class="btn btn-success">重置</button>
        </div>
    </div>
</form>
</div>
<script src="hplus-master/js/jquery.min.js?v=2.1.4"></script>
<script src="hplus-master/js/plugins/layer/layer.min.js"></script>
<script src="hplus-master/js/bootstrap.min.js?v=3.3.7"></script>
<script src="hplus-master/js/plugins/validate/jquery.validate.min.js"></script>
<script src="hplus-master/js/plugins/validate/messages_zh.min.js"></script>
</body>
<script>
    $(function () {

        $("#addForm").validate({
            rules:{
                loginName: {
                    required: true,
                    remote:{
                        url:'user/checkLoginName',
                        type:'post',
                        loginName:function(){
                            return $("#loginName1").val();
                        }
                    }
                },
                loginPwd:{
                    required:true
                },
                loginPwd2:{
                    required: true,
                    equalTo:"#loginPwd"
                },
                realName:'required',
                userBirthday:{
                    dateISO: true
                },
                userIdcard:{
                    maxlength:18,
                    minlength:18
                }

            },
            messages:{
                loginName:{
                    required:'<i class=\'fa fa-times-circle\'></i> 请输入用户名',
                    remote:'用户名已存在'
                },
                loginPwd2:{
                    equalTo:'两次输入密码不一致'
                },
                userIdcard: {
                    maxlength: '请输入正确的身份证号',
                    minlength:'请输入正确的身份证号'
                }

            }
        });



        $(".save").click(function(){
            // 对绑定的规则进行校验，如果校验通过，返回true,否则返回false
            if($("#addForm").valid()) {
                let params = $("#addForm").serialize();
                $.ajax({
                    url: 'user/save',
                    type: 'post',
                    dataType: 'json',
                    data: params,
                    success: function (ret) {

                        if (ret.code == 200) {
                            layer.msg(ret.msg, function () {
                                parent.close();
                            });

                        }
                        if (ret.code != 200) {
                            layer.msg(ret.msg);
                        }

                    }
                })
            }
        });
    })
</script>
</html>
